package com.boco.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.dao.GetEMR_ZYZDData;
import com.boco.dao.SentData;
import com.boco.entity.EMR_ZYZD;

public class InsertEMR_ZYZDDataAction {
	private static final Log log = LogFactory.getLog(InsertEMR_ZYZDDataAction.class);
	public  String insertData(){
		String url = "http://fasong.cdxp.csb/json/dzbl4";
		String resule = null;
		List<EMR_ZYZD> list = new ArrayList<EMR_ZYZD>();
		list = GetEMR_ZYZDData.getData();
		
	    log.info("########################################");
	    log.info("数据总条数："+list.size());
	    log.info("########################################");
		String userName = "dzbl4";
		String password = "322dfbf9048445cabb06cbf24e64cdcf";
		EMR_ZYZD temp = null;
		
		for(int i=0;i<list.size();i++){
			String param = null;
			temp = list.get(i);
			//log.info(temp.getXM());
			//按照身份证删除已经存在的值。
			param = "{\"SQL\":\"delete  EMR_ZYZD where ZYH='"+
					temp.getZYH()
					+"' and JZJGDM = '"+temp.getJZJGDM()+"'"
				
			
					+ "\", \"ANNOTION\":\"cdxplogs\"}";
			resule = SentData.sendPost(url, param, userName, password);
			log.info("删除结果："+resule);
			param = "{\"SQL\":\"INSERT INTO EMR_ZYZD ("
					+ "JZJGDM,"
					+ "ZYH,"
					+ "ZYZD_JBBM,"
					+ "ZYZDMC,"
					+ "ZDLX,"
					+ "HZZSYH,"
					+ "ZDXH,"
					+ "ZDRQ,"
					+ "BCRQ,"
					+ "ZRLSH,"
					+ "ORGCODE,"
					+ "AREACODE,"
					+ "UPLOADTIME,"
					+ "SOURCEID"
					+ ") VALUES("
					+ "'" + checkStr(temp.getJZJGDM()) + "'," 
					+ "'" + checkStr(temp.getZYH()) + "'," 
					+ "'" + checkStr(temp.getZYZD_JBBM()) + "'," 
					+ "'" + checkStr(temp.getZYZDMC()) + "'," 
					+ "'" + checkStr(temp.getZDLX()) + "',"
					+ "'" + checkStr(temp.getHZZSYH()) + "'," 
					+ "'" + checkStr(temp.getZDXH()) + "'," 
					+ "to_date('" + checkStr(temp.getZDRQ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					+ "to_date('" + checkStr(temp.getBCRQ()) + "','yyyy-MM-dd HH24:mi:ss'),"
					+ "'" + checkStr(temp.getZRLSH()) + "'," 
					+ "'" + checkStr(temp.getORGCODE()) + "'," 
					+ "'" + checkStr(temp.getAREACODE()) + "'," 
					+ "sysdate," 
					+ "'dzbl4'" 
					+ ")\", \"ANNOTION\":\"cdxplogs\"}";
					resule = SentData.sendPost(url, param, userName, password);
					log.info(resule);
					
		}
		log.info("上传完成！");
		return resule;
		
	
		
	}
	
	public static String checkStr(Object obj){
		if (obj== null){
			obj = "";
		}
		return (String) obj;
	}
	
	
}
